package BeheerBehandelingen.View;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class DocumentPopup extends JFrame
{
	private JPanel contentPane;
	private JButton btnOpslaan;

	private JLabel lblDocumentnaam;

	private File document;

	public DocumentPopup(String patientName)
	{
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setSize(350, 150);
		setResizable(false);
		contentPane = new JPanel();
		setContentPane(contentPane);
		contentPane.setLayout(new GridBagLayout());

		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		c.insets = new Insets(10, 10, 3, 3);
		c.weightx = 1.0;
		c.weighty = 1.0;
		c.gridx = 0;
		c.gridy = 0;

		JLabel lblPatient = new JLabel("Patient: ");
		contentPane.add(lblPatient, c);

		c.insets = new Insets(10, 3, 0, 10);
		c.gridx = 1;
		JLabel lblPatientnaam = new JLabel(patientName);
		contentPane.add(lblPatientnaam, c);

		c.insets = new Insets(0, 10, 10, 3);
		c.gridx = 0;
		c.gridy = 1;
		JLabel lblDocument = new JLabel("Document: ");
		contentPane.add(lblDocument, c);

		c.insets = new Insets(0, 0, 10, 10);
		c.gridx = 1;
		lblDocumentnaam = new JLabel();
		contentPane.add(lblDocumentnaam, c);

		JButton btnSelecteerDocument = new JButton("Selecteer Document");
		btnSelecteerDocument.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				JFileChooser fc = new JFileChooser();
				fc.showOpenDialog(DocumentPopup.this);
				
				if (fc.getSelectedFile() != null)
					lblDocumentnaam.setText(fc.getSelectedFile().getName());
				
				DocumentPopup.this.document = fc.getSelectedFile();
			}
		});
		c.insets = new Insets(0, 10, 10, 10);
		c.gridx = 0;
		c.gridy = 2;
		c.gridwidth = 4;
		contentPane.add(btnSelecteerDocument, c);

		c.gridy = 3;
		c.gridwidth = 1;
		btnOpslaan = new JButton("Opslaan");
		btnOpslaan.setActionCommand("opslaan");
		contentPane.add(btnOpslaan, c);

		c.gridx = 3;
		JButton btnAnnuleren = new JButton("Annuleren");
		btnAnnuleren.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				DocumentPopup.this.dispose();
			}
		});
		contentPane.add(btnAnnuleren, c);

		setTitle("Document Koppelen");
		setLocationRelativeTo(null);
		setVisible(true);
	}

	public void setListener(ActionListener listener)
	{
		btnOpslaan.addActionListener(listener);
	}

	public File getDocument()
	{
		return document;
	}
}
